/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package xyz.litecoder.demos;

import java.io.FileNotFoundException;

import xyz.litecoder.demos.ColorPickerDialog.OnColorChangedListener;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity implements OnColorChangedListener {


	private ZImageView z;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_teach_exam_view);
		z=(ZImageView)findViewById(R.id.imageView);
	}

	public void colorChanged(int color) {
		z.drawMode();
		z.setColor(color);
	}

	private static final int COLOR_MENU_ID = Menu.FIRST;
	private static final int ERASE_MENU_ID = Menu.FIRST + 1;
	private static final int SAVE_MENU_ID = Menu.FIRST + 2;
	private static final int SCROLL_MENU_ID = Menu.FIRST + 3;

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0, COLOR_MENU_ID, 0, "颜色").setShortcut('3', 'c');
		menu.add(0, ERASE_MENU_ID, 0, "橡皮擦").setShortcut('5', 'z');
		menu.add(0, SAVE_MENU_ID, 0, "保存笔迹").setShortcut('6', 'z');
		menu.add(0, SCROLL_MENU_ID, 0, "滚动").setShortcut('7', 'g');
		return true;
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		super.onPrepareOptionsMenu(menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case COLOR_MENU_ID:
			new ColorPickerDialog(this, this, z.getColor()).show();
			return true;
		case SCROLL_MENU_ID:
			z.scrollMode();
			return true;
		case ERASE_MENU_ID:
			z.clearMode();
			return true;
		case SAVE_MENU_ID:
			try {
				z.saveToFile("/sdcard/temp/drawTemp.png");
				Log.d(getPackageName(), "/sdcard/temp/drawTemp.png");
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
